package com.bdqn.service;

import com.bdqn.mapper.SysUserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

/**
 * TestService
 *
 * @author LILIBO
 * @since 2024/12/6
 */
public class TestService {

    public static void main(String[] args) {
        // 定义配置文件位置
        String rssource = "mybatis-config.xml";
        // 数据库连接对象SqlSession
        SqlSession session = null;
        // 加载配置文件
        try {
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream(rssource));
            session = sqlSessionFactory.openSession();
            int count = session.getMapper(SysUserMapper.class).count();
            System.out.println("用户数量：" + count);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭资源
            if (session != null) {
                session.close();
            }
        }
    }

}
